<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" th:href="@{/lib/layui-v2.6.5/css/layui.css}" media="all">
    <link rel="stylesheet" th:href="@{/css/public.css}" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>

<div th:replace="~{sys-role/component::form('确认保存')}"></div>

<script th:src="@{/lib/layui-v2.6.5/layui.js}" charset="utf-8"></script>
<script>
    layui.use(['form'], function () {
        var form = layui.form,
            $ = layui.$

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            $.ajax({
                type: "POST",
                url: "/sys-user-api/add",
                data: data.field,
                dataType: "json",
                success: function (data) {
                    if (data.code === 0) {
                        parent.layer.msg('添加成功')
                        let iframeIndex = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(iframeIndex);
                        parent.layui.table.reload('user-list-table', {
                            url: '/sys-user-api/list'
                        });
                    } else {
                        parent.layer.open({
                            title: 'error',
                            content: data.msg
                        })
                    }
                },
                error: function (obj, data, err) {
                    parent.layer.open({
                        title: 'error',
                        content: data
                    })
                }
            })
            return false;
        });
    });
</script>
</body>
</html>